package com.lagou.demo.controller;

import com.lagou.demo.config.ServiceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class LoginController {
    @Autowired
    private ServiceConfig serviceConfig;

    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/getLogin")
    public String loginHtml(ModelMap model){
        model.put("url",serviceConfig.getUrl());
        HttpSession session = request.getSession();
        model.put("sessionid",session.getId());
        //已经登录过的用户
        if(session.getAttribute("sessionId")!=null){
            return "index";
        }
        return "login";
    }

    /**
     * 登录主页
     *
     * @return String
     */
    @RequestMapping("index")
    public String index(ModelMap model){
        model.put("sessionid",request.getSession().getId());
        return "index";
    }
}
